package documenteditor;

import java.io.*;
import goldengine.java.*;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/*
 * Licensed Material - Property of Matthew Hawkins (hawkini@4email.net) 
 */
public class DecafParser implements GPMessageConstants
{

    private interface SymbolConstants 
    {
       final int SYMBOL_EOF                   =  0;  // (EOF)
       final int SYMBOL_ERROR                 =  1;  // (Error)
       final int SYMBOL_WHITESPACE            =  2;  // (Whitespace)
       final int SYMBOL_MINUS                 =  3;  // '-'
       final int SYMBOL_EXCLAM                =  4;  // '!'
       final int SYMBOL_EXCLAMEQ              =  5;  // '!='
       final int SYMBOL_PERCENT               =  6;  // '%'
       final int SYMBOL_AMPAMP                =  7;  // '&&'
       final int SYMBOL_LPARAN                =  8;  // '('
       final int SYMBOL_RPARAN                =  9;  // ')'
       final int SYMBOL_TIMES                 = 10;  // '*'
       final int SYMBOL_COMMA                 = 11;  // ','
       final int SYMBOL_DOT                   = 12;  // '.'
       final int SYMBOL_DIV                   = 13;  // '/'
       final int SYMBOL_SEMI                  = 14;  // ';'
       final int SYMBOL_LBRACKET              = 15;  // '['
       final int SYMBOL_RBRACKET              = 16;  // ']'
       final int SYMBOL_LBRACE                = 17;  // '{'
       final int SYMBOL_PIPEPIPE              = 18;  // '||'
       final int SYMBOL_RBRACE                = 19;  // '}'
       final int SYMBOL_PLUS                  = 20;  // '+'
       final int SYMBOL_LT                    = 21;  // '<'
       final int SYMBOL_LTEQ                  = 22;  // '<='
       final int SYMBOL_EQ                    = 23;  // '='
       final int SYMBOL_EQEQ                  = 24;  // '=='
       final int SYMBOL_GT                    = 25;  // '>'
       final int SYMBOL_GTEQ                  = 26;  // '>='
       final int SYMBOL_BOOLEAN               = 27;  // boolean
       final int SYMBOL_CHAR                  = 28;  // char
       final int SYMBOL_CHARACTER             = 29;  // character
       final int SYMBOL_CLASS                 = 30;  // class
       final int SYMBOL_ELSE                  = 31;  // else
       final int SYMBOL_FALSE                 = 32;  // false
       final int SYMBOL_ID                    = 33;  // id
       final int SYMBOL_IF                    = 34;  // if
       final int SYMBOL_INT                   = 35;  // int
       final int SYMBOL_NUM                   = 36;  // num
       final int SYMBOL_PROGRAM               = 37;  // Program
       final int SYMBOL_RETURN                = 38;  // return
       final int SYMBOL_STRUCT                = 39;  // struct
       final int SYMBOL_TRUE                  = 40;  // true
       final int SYMBOL_VOID                  = 41;  // void
       final int SYMBOL_WHILE                 = 42;  // while
       final int SYMBOL_ADDEXP                = 43;  // <Add Exp>
       final int SYMBOL_ADDOP                 = 44;  // <addop>
       final int SYMBOL_ARG                   = 45;  // <arg>
       final int SYMBOL_ARGLIST               = 46;  // <arg list>
       final int SYMBOL_ASSIGN                = 47;  // <assign>
       final int SYMBOL_BLOCK                 = 48;  // <block>
       final int SYMBOL_BOOL_LITERAL          = 49;  // <bool_literal>
       final int SYMBOL_CHAR_LITERAL          = 50;  // <char_literal>
       final int SYMBOL_CONDITIONALOP         = 51;  // <conditionalop>
       final int SYMBOL_DECLARATION           = 52;  // <declaration>
       final int SYMBOL_EXPRESSION            = 53;  // <expression>
       final int SYMBOL_INT_LITERAL           = 54;  // <int_literal>
       final int SYMBOL_ITERATION             = 55;  // <iteration>
       final int SYMBOL_KLEENE_DECLARATION    = 56;  // <kleene_declaration>
       final int SYMBOL_KLEENE_STATEMENT      = 57;  // <kleene_statement>
       final int SYMBOL_KLEENE_VARDECLARATION = 58;  // <kleene_varDeclaration>
       final int SYMBOL_LITERAL               = 59;  // <literal>
       final int SYMBOL_LOCATION              = 60;  // <location>
       final int SYMBOL_METHODCALL            = 61;  // <methodCall>
       final int SYMBOL_METHODDECLARATION     = 62;  // <methodDeclaration>
       final int SYMBOL_MULOP                 = 63;  // <mulop>
       final int SYMBOL_MULTEXP               = 64;  // <Mult Exp>
       final int SYMBOL_NEGATEEXP             = 65;  // <Negate Exp>
       final int SYMBOL_OPT_ARG_SEPARATED     = 66;  // <opt_arg_separated>
       final int SYMBOL_OPT_ELSE_BLOCK        = 67;  // <opt_else_block>
       final int SYMBOL_OPT_EXPRESSION        = 68;  // <opt_expression>
       final int SYMBOL_OPT_PARAMETER         = 69;  // <opt_parameter>
       final int SYMBOL_PARAMETER             = 70;  // <parameter>
       final int SYMBOL_PARAMETERLIST         = 71;  // <parameter list>
       final int SYMBOL_PROGRAM2              = 72;  // <Program>
       final int SYMBOL_RELEXP                = 73;  // <Rel Exp>
       final int SYMBOL_RELOP                 = 74;  // <relop>
       final int SYMBOL_RETURN2               = 75;  // <return>
       final int SYMBOL_SELECTION             = 76;  // <selection>
       final int SYMBOL_SIMPLELOCATION        = 77;  // <simpleLocation>
       final int SYMBOL_STATEMENT             = 78;  // <statement>
       final int SYMBOL_STRUCTDECLARATION     = 79;  // <structDeclaration>
       final int SYMBOL_TYPE                  = 80;  // <Type>
       final int SYMBOL_VALUE                 = 81;  // <Value>
       final int SYMBOL_VARDECL1              = 82;  // <varDecl 1>
       final int SYMBOL_VARDECLARATION        = 83;  // <varDeclaration>
    };

    private interface RuleConstants
    {
       final int RULE_PROGRAM_CLASS_PROGRAM_LBRACE_RBRACE       =  0;  // <Program> ::= class Program '{' <kleene_declaration> '}'
       final int RULE_KLEENE_DECLARATION                        =  1;  // <kleene_declaration> ::= <declaration> <kleene_declaration>
       final int RULE_KLEENE_DECLARATION2                       =  2;  // <kleene_declaration> ::= 
       final int RULE_DECLARATION                               =  3;  // <declaration> ::= <structDeclaration>
       final int RULE_DECLARATION2                              =  4;  // <declaration> ::= <varDeclaration>
       final int RULE_DECLARATION3                              =  5;  // <declaration> ::= <methodDeclaration>
       final int RULE_VARDECLARATION_ID_SEMI                    =  6;  // <varDeclaration> ::= <Type> id <varDecl 1> ';'
       final int RULE_VARDECL1_LBRACKET_NUM_RBRACKET            =  7;  // <varDecl 1> ::= '[' num ']'
       final int RULE_VARDECL1                                  =  8;  // <varDecl 1> ::= 
       final int RULE_STRUCTDECLARATION_STRUCT_ID_LBRACE_RBRACE =  9;  // <structDeclaration> ::= struct id '{' <kleene_varDeclaration> '}'
       final int RULE_KLEENE_VARDECLARATION                     = 10;  // <kleene_varDeclaration> ::= <varDeclaration> <kleene_varDeclaration>
       final int RULE_KLEENE_VARDECLARATION2                    = 11;  // <kleene_varDeclaration> ::= 
       final int RULE_METHODDECLARATION_ID_LPARAN_RPARAN        = 12;  // <methodDeclaration> ::= <Type> id '(' <opt_parameter> ')' <block>
       final int RULE_OPT_PARAMETER                             = 13;  // <opt_parameter> ::= <parameter list>
       final int RULE_OPT_PARAMETER2                            = 14;  // <opt_parameter> ::= 
       final int RULE_PARAMETERLIST                             = 15;  // <parameter list> ::= <parameter>
       final int RULE_PARAMETERLIST_COMMA                       = 16;  // <parameter list> ::= <parameter list> ',' <parameter>
       final int RULE_TYPE_INT                                  = 17;  // <Type> ::= int
       final int RULE_TYPE_CHAR                                 = 18;  // <Type> ::= char
       final int RULE_TYPE_BOOLEAN                              = 19;  // <Type> ::= boolean
       final int RULE_TYPE_VOID                                 = 20;  // <Type> ::= void
       final int RULE_TYPE_STRUCT_ID                            = 21;  // <Type> ::= struct id
       final int RULE_TYPE                                      = 22;  // <Type> ::= <structDeclaration>
       final int RULE_PARAMETER_ID                              = 23;  // <parameter> ::= <Type> id
       final int RULE_PARAMETER_ID_LBRACKET_RBRACKET            = 24;  // <parameter> ::= <Type> id '[' ']'
       final int RULE_BLOCK_LBRACE_RBRACE                       = 25;  // <block> ::= '{' <kleene_varDeclaration> <kleene_statement> '}'
       final int RULE_KLEENE_STATEMENT                          = 26;  // <kleene_statement> ::= <statement> <kleene_statement>
       final int RULE_KLEENE_STATEMENT2                         = 27;  // <kleene_statement> ::= 
       final int RULE_STATEMENT                                 = 28;  // <statement> ::= <block>
       final int RULE_STATEMENT2                                = 29;  // <statement> ::= <selection>
       final int RULE_STATEMENT3                                = 30;  // <statement> ::= <iteration>
       final int RULE_STATEMENT_SEMI                            = 31;  // <statement> ::= <return> ';'
       final int RULE_STATEMENT_SEMI2                           = 32;  // <statement> ::= <assign> ';'
       final int RULE_STATEMENT_SEMI3                           = 33;  // <statement> ::= <opt_expression> ';'
       final int RULE_SELECTION_IF_LPARAN_RPARAN                = 34;  // <selection> ::= if '(' <expression> ')' <block> <opt_else_block>
       final int RULE_OPT_ELSE_BLOCK_ELSE                       = 35;  // <opt_else_block> ::= else <block>
       final int RULE_OPT_ELSE_BLOCK                            = 36;  // <opt_else_block> ::= 
       final int RULE_ITERATION_WHILE_LPARAN_RPARAN             = 37;  // <iteration> ::= while '(' <expression> ')' <block>
       final int RULE_RETURN_RETURN                             = 38;  // <return> ::= return <opt_expression>
       final int RULE_ASSIGN_EQ                                 = 39;  // <assign> ::= <location> '=' <expression>
       final int RULE_OPT_EXPRESSION                            = 40;  // <opt_expression> ::= <expression>
       final int RULE_OPT_EXPRESSION2                           = 41;  // <opt_expression> ::= 
       final int RULE_EXPRESSION                                = 42;  // <expression> ::= <Rel Exp> <conditionalop> <expression>
       final int RULE_EXPRESSION2                               = 43;  // <expression> ::= <Rel Exp>
       final int RULE_RELEXP                                    = 44;  // <Rel Exp> ::= <Add Exp> <relop> <Rel Exp>
       final int RULE_RELEXP2                                   = 45;  // <Rel Exp> ::= <Add Exp>
       final int RULE_ADDEXP                                    = 46;  // <Add Exp> ::= <Mult Exp> <addop> <Add Exp>
       final int RULE_ADDEXP2                                   = 47;  // <Add Exp> ::= <Mult Exp>
       final int RULE_MULTEXP                                   = 48;  // <Mult Exp> ::= <Negate Exp> <mulop> <Mult Exp>
       final int RULE_MULTEXP2                                  = 49;  // <Mult Exp> ::= <Negate Exp>
       final int RULE_NEGATEEXP_MINUS                           = 50;  // <Negate Exp> ::= '-' <Value>
       final int RULE_NEGATEEXP_EXCLAM                          = 51;  // <Negate Exp> ::= '!' <Value>
       final int RULE_NEGATEEXP                                 = 52;  // <Negate Exp> ::= <Value>
       final int RULE_CONDITIONALOP_AMPAMP                      = 53;  // <conditionalop> ::= '&&'
       final int RULE_CONDITIONALOP_PIPEPIPE                    = 54;  // <conditionalop> ::= '||'
       final int RULE_RELOP_LTEQ                                = 55;  // <relop> ::= '<='
       final int RULE_RELOP_LT                                  = 56;  // <relop> ::= '<'
       final int RULE_RELOP_GT                                  = 57;  // <relop> ::= '>'
       final int RULE_RELOP_GTEQ                                = 58;  // <relop> ::= '>='
       final int RULE_RELOP_EQEQ                                = 59;  // <relop> ::= '=='
       final int RULE_RELOP_EXCLAMEQ                            = 60;  // <relop> ::= '!='
       final int RULE_ADDOP_PLUS                                = 61;  // <addop> ::= '+'
       final int RULE_ADDOP_MINUS                               = 62;  // <addop> ::= '-'
       final int RULE_MULOP_TIMES                               = 63;  // <mulop> ::= '*'
       final int RULE_MULOP_DIV                                 = 64;  // <mulop> ::= '/'
       final int RULE_MULOP_PERCENT                             = 65;  // <mulop> ::= '%'
       final int RULE_VALUE                                     = 66;  // <Value> ::= <literal>
       final int RULE_VALUE_LPARAN_RPARAN                       = 67;  // <Value> ::= '(' <expression> ')'
       final int RULE_VALUE2                                    = 68;  // <Value> ::= <methodCall>
       final int RULE_VALUE3                                    = 69;  // <Value> ::= <location>
       final int RULE_LOCATION_DOT                              = 70;  // <location> ::= <simpleLocation> '.' <location>
       final int RULE_LOCATION                                  = 71;  // <location> ::= <simpleLocation>
       final int RULE_SIMPLELOCATION_ID_LBRACKET_RBRACKET       = 72;  // <simpleLocation> ::= id '[' <expression> ']'
       final int RULE_SIMPLELOCATION_ID                         = 73;  // <simpleLocation> ::= id
       final int RULE_METHODCALL_ID_LPARAN_RPARAN               = 74;  // <methodCall> ::= id '(' <opt_arg_separated> ')'
       final int RULE_OPT_ARG_SEPARATED                         = 75;  // <opt_arg_separated> ::= <arg list>
       final int RULE_OPT_ARG_SEPARATED2                        = 76;  // <opt_arg_separated> ::= 
       final int RULE_ARGLIST                                   = 77;  // <arg list> ::= <arg>
       final int RULE_ARGLIST_COMMA                             = 78;  // <arg list> ::= <arg list> ',' <arg>
       final int RULE_ARG                                       = 79;  // <arg> ::= <expression>
       final int RULE_LITERAL                                   = 80;  // <literal> ::= <int_literal>
       final int RULE_LITERAL2                                  = 81;  // <literal> ::= <char_literal>
       final int RULE_LITERAL3                                  = 82;  // <literal> ::= <bool_literal>
       final int RULE_INT_LITERAL_NUM                           = 83;  // <int_literal> ::= num
       final int RULE_CHAR_LITERAL_CHARACTER                    = 84;  // <char_literal> ::= character
       final int RULE_BOOL_LITERAL_TRUE                         = 85;  // <bool_literal> ::= true
       final int RULE_BOOL_LITERAL_FALSE                        = 86;  // <bool_literal> ::= false
    };

    public DecafParser(){}

    public void All(){

        //GOLDParser parser = new GOLDParser();
        try{
            parser.loadCompiledGrammar(this.compiledGrammar);
            parser.openFile(textToParse);
        }
       catch(ParserException parse){

           System.out.println("**PARSER ERROR**\n" + parse.toString());
           //System.exit(1);
           this.error = true;
           this.error_log+="** PARSER ERROR ** "+"\n\t"+ parse.toString() +"\n";
       }

       boolean done = false;
       int response = -1;

       while(!done)
       {

           try
           {
               response = parser.parse();
           }
           catch(ParserException parse)
           {
               System.out.println("**PARSER ERROR**\n" + parse.toString());
               //System.exit(1);
               this.error = true;
               this.error_log+="** PARSER ERROR ** "+"\n\t"+ parse.toString() +"\n";
           }

           switch(response)
           {
               case gpMsgTokenRead:
                   /* A token was read by the parser. The Token Object can be accessed
                      through the CurrentToken() property:  Parser.CurrentToken */
                   break;

               case gpMsgReduction:
                   /* This message is returned when a rule was reduced by the parse engine.
                      The CurrentReduction property is assigned a Reduction object
                      containing the rule and its related tokens. You can reassign this
                      property to your own customized class. If this is not the case,
                      this message can be ignored and the Reduction object will be used
                      to store the parse tree.  */

                      switch(parser.currentReduction().getParentRule().getTableIndex())
                      {
                         case RuleConstants.RULE_PROGRAM_CLASS_PROGRAM_LBRACE_RBRACE:
                            //<Program> ::= class Program '{' <kleene_declaration> '}'
                            break;
                         case RuleConstants.RULE_KLEENE_DECLARATION:
                            //<kleene_declaration> ::= <declaration> <kleene_declaration>
                            break;
                         case RuleConstants.RULE_KLEENE_DECLARATION2:
                            //<kleene_declaration> ::= 
                            break;
                         case RuleConstants.RULE_DECLARATION:
                            //<declaration> ::= <structDeclaration>
                            break;
                         case RuleConstants.RULE_DECLARATION2:
                            //<declaration> ::= <varDeclaration>
                            break;
                         case RuleConstants.RULE_DECLARATION3:
                            //<declaration> ::= <methodDeclaration>
                            break;
                         case RuleConstants.RULE_VARDECLARATION_ID_SEMI:
                            //<varDeclaration> ::= <Type> id <varDecl 1> ';'
                            break;
                         case RuleConstants.RULE_VARDECL1_LBRACKET_NUM_RBRACKET:
                            //<varDecl 1> ::= '[' num ']'
                            break;
                         case RuleConstants.RULE_VARDECL1:
                            //<varDecl 1> ::= 
                            break;
                         case RuleConstants.RULE_STRUCTDECLARATION_STRUCT_ID_LBRACE_RBRACE:
                            //<structDeclaration> ::= struct id '{' <kleene_varDeclaration> '}'
                            break;
                         case RuleConstants.RULE_KLEENE_VARDECLARATION:
                            //<kleene_varDeclaration> ::= <varDeclaration> <kleene_varDeclaration>
                            break;
                         case RuleConstants.RULE_KLEENE_VARDECLARATION2:
                            //<kleene_varDeclaration> ::= 
                            break;
                         case RuleConstants.RULE_METHODDECLARATION_ID_LPARAN_RPARAN:
                            //<methodDeclaration> ::= <Type> id '(' <opt_parameter> ')' <block>
                            break;
                         case RuleConstants.RULE_OPT_PARAMETER:
                            //<opt_parameter> ::= <parameter list>
                            break;
                         case RuleConstants.RULE_OPT_PARAMETER2:
                            //<opt_parameter> ::= 
                            break;
                         case RuleConstants.RULE_PARAMETERLIST:
                            //<parameter list> ::= <parameter>
                            break;
                         case RuleConstants.RULE_PARAMETERLIST_COMMA:
                            //<parameter list> ::= <parameter list> ',' <parameter>
                            break;
                         case RuleConstants.RULE_TYPE_INT:
                            //<Type> ::= int
                            break;
                         case RuleConstants.RULE_TYPE_CHAR:
                            //<Type> ::= char
                            break;
                         case RuleConstants.RULE_TYPE_BOOLEAN:
                            //<Type> ::= boolean
                            break;
                         case RuleConstants.RULE_TYPE_VOID:
                            //<Type> ::= void
                            break;
                         case RuleConstants.RULE_TYPE_STRUCT_ID:
                            //<Type> ::= struct id
                            break;
                         case RuleConstants.RULE_TYPE:
                            //<Type> ::= <structDeclaration>
                            break;
                         case RuleConstants.RULE_PARAMETER_ID:
                            //<parameter> ::= <Type> id
                            break;
                         case RuleConstants.RULE_PARAMETER_ID_LBRACKET_RBRACKET:
                            //<parameter> ::= <Type> id '[' ']'
                            break;
                         case RuleConstants.RULE_BLOCK_LBRACE_RBRACE:
                            //<block> ::= '{' <kleene_varDeclaration> <kleene_statement> '}'
                            break;
                         case RuleConstants.RULE_KLEENE_STATEMENT:
                            //<kleene_statement> ::= <statement> <kleene_statement>
                            break;
                         case RuleConstants.RULE_KLEENE_STATEMENT2:
                            //<kleene_statement> ::= 
                            break;
                         case RuleConstants.RULE_STATEMENT:
                            //<statement> ::= <block>
                            break;
                         case RuleConstants.RULE_STATEMENT2:
                            //<statement> ::= <selection>
                            break;
                         case RuleConstants.RULE_STATEMENT3:
                            //<statement> ::= <iteration>
                            break;
                         case RuleConstants.RULE_STATEMENT_SEMI:
                            //<statement> ::= <return> ';'
                            break;
                         case RuleConstants.RULE_STATEMENT_SEMI2:
                            //<statement> ::= <assign> ';'
                            break;
                         case RuleConstants.RULE_STATEMENT_SEMI3:
                            //<statement> ::= <opt_expression> ';'
                            break;
                         case RuleConstants.RULE_SELECTION_IF_LPARAN_RPARAN:
                            //<selection> ::= if '(' <expression> ')' <block> <opt_else_block>
                            break;
                         case RuleConstants.RULE_OPT_ELSE_BLOCK_ELSE:
                            //<opt_else_block> ::= else <block>
                            break;
                         case RuleConstants.RULE_OPT_ELSE_BLOCK:
                            //<opt_else_block> ::= 
                            break;
                         case RuleConstants.RULE_ITERATION_WHILE_LPARAN_RPARAN:
                            //<iteration> ::= while '(' <expression> ')' <block>
                            break;
                         case RuleConstants.RULE_RETURN_RETURN:
                            //<return> ::= return <opt_expression>
                            break;
                         case RuleConstants.RULE_ASSIGN_EQ:
                            //<assign> ::= <location> '=' <expression>
                            break;
                         case RuleConstants.RULE_OPT_EXPRESSION:
                            //<opt_expression> ::= <expression>
                            break;
                         case RuleConstants.RULE_OPT_EXPRESSION2:
                            //<opt_expression> ::= 
                            break;
                         case RuleConstants.RULE_EXPRESSION:
                            //<expression> ::= <Rel Exp> <conditionalop> <expression>
                            break;
                         case RuleConstants.RULE_EXPRESSION2:
                            //<expression> ::= <Rel Exp>
                            break;
                         case RuleConstants.RULE_RELEXP:
                            //<Rel Exp> ::= <Add Exp> <relop> <Rel Exp>
                            break;
                         case RuleConstants.RULE_RELEXP2:
                            //<Rel Exp> ::= <Add Exp>
                            break;
                         case RuleConstants.RULE_ADDEXP:
                            //<Add Exp> ::= <Mult Exp> <addop> <Add Exp>
                            break;
                         case RuleConstants.RULE_ADDEXP2:
                            //<Add Exp> ::= <Mult Exp>
                            break;
                         case RuleConstants.RULE_MULTEXP:
                            //<Mult Exp> ::= <Negate Exp> <mulop> <Mult Exp>
                            break;
                         case RuleConstants.RULE_MULTEXP2:
                            //<Mult Exp> ::= <Negate Exp>
                            break;
                         case RuleConstants.RULE_NEGATEEXP_MINUS:
                            //<Negate Exp> ::= '-' <Value>
                            break;
                         case RuleConstants.RULE_NEGATEEXP_EXCLAM:
                            //<Negate Exp> ::= '!' <Value>
                            break;
                         case RuleConstants.RULE_NEGATEEXP:
                            //<Negate Exp> ::= <Value>
                            break;
                         case RuleConstants.RULE_CONDITIONALOP_AMPAMP:
                            //<conditionalop> ::= '&&'
                            break;
                         case RuleConstants.RULE_CONDITIONALOP_PIPEPIPE:
                            //<conditionalop> ::= '||'
                            break;
                         case RuleConstants.RULE_RELOP_LTEQ:
                            //<relop> ::= '<='
                            break;
                         case RuleConstants.RULE_RELOP_LT:
                            //<relop> ::= '<'
                            break;
                         case RuleConstants.RULE_RELOP_GT:
                            //<relop> ::= '>'
                            break;
                         case RuleConstants.RULE_RELOP_GTEQ:
                            //<relop> ::= '>='
                            break;
                         case RuleConstants.RULE_RELOP_EQEQ:
                            //<relop> ::= '=='
                            break;
                         case RuleConstants.RULE_RELOP_EXCLAMEQ:
                            //<relop> ::= '!='
                            break;
                         case RuleConstants.RULE_ADDOP_PLUS:
                            //<addop> ::= '+'
                            break;
                         case RuleConstants.RULE_ADDOP_MINUS:
                            //<addop> ::= '-'
                            break;
                         case RuleConstants.RULE_MULOP_TIMES:
                            //<mulop> ::= '*'
                            break;
                         case RuleConstants.RULE_MULOP_DIV:
                            //<mulop> ::= '/'
                            break;
                         case RuleConstants.RULE_MULOP_PERCENT:
                            //<mulop> ::= '%'
                            break;
                         case RuleConstants.RULE_VALUE:
                            //<Value> ::= <literal>
                            break;
                         case RuleConstants.RULE_VALUE_LPARAN_RPARAN:
                            //<Value> ::= '(' <expression> ')'
                            break;
                         case RuleConstants.RULE_VALUE2:
                            //<Value> ::= <methodCall>
                            break;
                         case RuleConstants.RULE_VALUE3:
                            //<Value> ::= <location>
                            break;
                         case RuleConstants.RULE_LOCATION_DOT:
                            //<location> ::= <simpleLocation> '.' <location>
                            break;
                         case RuleConstants.RULE_LOCATION:
                            //<location> ::= <simpleLocation>
                            break;
                         case RuleConstants.RULE_SIMPLELOCATION_ID_LBRACKET_RBRACKET:
                            //<simpleLocation> ::= id '[' <expression> ']'
                            break;
                         case RuleConstants.RULE_SIMPLELOCATION_ID:
                            //<simpleLocation> ::= id
                            break;
                         case RuleConstants.RULE_METHODCALL_ID_LPARAN_RPARAN:
                            //<methodCall> ::= id '(' <opt_arg_separated> ')'
                            break;
                         case RuleConstants.RULE_OPT_ARG_SEPARATED:
                            //<opt_arg_separated> ::= <arg list>
                            break;
                         case RuleConstants.RULE_OPT_ARG_SEPARATED2:
                            //<opt_arg_separated> ::= 
                            break;
                         case RuleConstants.RULE_ARGLIST:
                            //<arg list> ::= <arg>
                            break;
                         case RuleConstants.RULE_ARGLIST_COMMA:
                            //<arg list> ::= <arg list> ',' <arg>
                            break;
                         case RuleConstants.RULE_ARG:
                            //<arg> ::= <expression>
                            break;
                         case RuleConstants.RULE_LITERAL:
                            //<literal> ::= <int_literal>
                            break;
                         case RuleConstants.RULE_LITERAL2:
                            //<literal> ::= <char_literal>
                            break;
                         case RuleConstants.RULE_LITERAL3:
                            //<literal> ::= <bool_literal>
                            break;
                         case RuleConstants.RULE_INT_LITERAL_NUM:
                            //<int_literal> ::= num
                            break;
                         case RuleConstants.RULE_CHAR_LITERAL_CHARACTER:
                            //<char_literal> ::= character
                            break;
                         case RuleConstants.RULE_BOOL_LITERAL_TRUE:
                            //<bool_literal> ::= true
                            break;
                         case RuleConstants.RULE_BOOL_LITERAL_FALSE:
                            //<bool_literal> ::= false
                            break;
                      }

                          //Parser.Reduction = //Object you created to store the rule

                    // ************************************** log file
                    System.out.println("gpMsgReduction");
                    Reduction myRed = parser.currentReduction();
                    this.debug_log+="gpMsgReduction (Line "+parser.currentLineNumber()+"): "+"\n\t"+ myRed.getParentRule().getText() +"\n";
                    System.out.println(myRed.getParentRule().getText());
                    // ************************************** end log

                    break;

                case gpMsgAccept:
                    /* The program was accepted by the parsing engine */
                    // ************************************** log file
                    this.error = false;
                    this.output_log += "gpMsgAccept";
                    System.out.println("gpMsgAccept");
                    // ************************************** end log
                    done = true;

                    break;

                case gpMsgLexicalError:
                    /* Place code here to handle a illegal or unrecognized token
                           To recover, pop the token from the stack: Parser.PopInputToken */
                    // ************************************** log file
                    this.error = true;
                    Token token = parser.popInputToken();
                    this.error_log += "gpMsgLexicalError (Line "+parser.currentLineNumber()+"): " +"\n\tIllegal or unrecognized token: "+ (String)token.getData();
                    System.out.println("gpMsgLexicalError");
                    // ************************************** end log
                    done = true;

                    break;

                case gpMsgNotLoadedError:
                    /* Load the Compiled Grammar Table file first. */

                    // ************************************** log file
                    this.error = true;
                    this.error_log += "gpMsgNotLoadedError (Line "+parser.currentLineNumber()+"): " +"\n\t"+ "Load the Compiled Grammar Table file first.";
                    System.out.println("gpMsgNotLoadedError");
                    // ************************************** end log

                    done = true;

                    break;

                case gpMsgSyntaxError:
                    /* This is a syntax error: the source has produced a token that was
                           not expected by the LALR State Machine. The expected tokens are stored
                           into the Tokens() list. To recover, push one of the
                              expected tokens onto the parser's input queue (the first in this case):
                           You should limit the number of times this type of recovery can take
                           place. */

                    done = true;

                    Token theTok = parser.currentToken();
                    System.out.println("Token not expected: " + (String)theTok.getData());

                    // ************************************** log file
                    this.error = true;
                    this.error_log += "gpMsgSyntaxError (Line "+parser.currentLineNumber()+"): " +"\n\t"+ "Token not expected: "+ (String)theTok.getData();
                    System.out.println("gpMsgSyntaxError");
                    // ************************************** end log

                    break;

                case gpMsgCommentError:
                    /* The end of the input was reached while reading a comment.
                             This is caused by a comment that was not terminated */

                    // ************************************** log file
                    this.error = true;
                    this.error_log += "gpMsgCommentError (Line "+parser.currentLineNumber()+"): " +"\n\t"+ "The end of the input was reached while reading a comment.";
                    System.out.println("gpMsgCommentError");
                    // ************************************** end log
                    done = true;
                    break;

                case gpMsgInternalError:
                    /* Something horrid happened inside the parser. You cannot recover */

                    // ************************************** log file
                    this.error = true;
                    this.error_log += "gpMsgInternalError (Line "+parser.currentLineNumber()+"): " +"\n\t"+ "Something horrid happened inside the parser. You cannot recover";
                    System.out.println("gpMsgInternalError");
                    // ************************************** end log
                    done = true;
                    break;
            }
        }
    }

    public static void showTree(DefaultTreeModel tree, DefaultMutableTreeNode root, Reduction reduccion){
        
        for(int i=0; i<reduccion.getTokenCount(); i++)
        {
            if(reduccion.getToken(i).getKind()==0){
                //Here comes when there is a non terminal. Example: <a> ::= 'b' <a> | 'c'
                Reduction red = (Reduction)reduccion.getToken(i).getData();
                String rule = red.getParentRule().definition();
                String rule_name = reduccion.getToken(i).getName();
                System.out.println(" + "+rule_name+ " + ."+rule+".");

                //TODO hacer comparaciones...

                DefaultMutableTreeNode child = new DefaultMutableTreeNode(reduccion.getToken(i).getName());
                showTree(tree, child, (Reduction)reduccion.getToken(i).getData());
                tree.insertNodeInto(child, root, i);
            }

            else{
                // Here comes when there is a terminal -> token
                // Token -> (name token, token lexeme)
                // This will be a leaf

                String token_name = reduccion.getToken(i).getName();
                String token_lexeme = (String)reduccion.getToken(i).getData();
                String txt_in_leaf = "";
                if(token_name.equals(token_lexeme) == true && token_name.equals("id")==false){
                    txt_in_leaf = token_name+"";
                }
                else{
                    txt_in_leaf = token_name + " = "+ token_lexeme;
                }
                System.out.println(" - "+txt_in_leaf);
                DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(txt_in_leaf);
                tree.insertNodeInto(leaf, root, i);
            }
        }
    }

    /***************************************************************
     * This class will run the engine, and needs a file called config.dat
     * in the current directory. This file should contain two lines,
     * The first should be the absolute path name to the .cgt file, the second
     * should be the source file you wish to parse.
     * @param args Array of arguments.
    ***************************************************************/
    public void Parse(String textToParse){

        this.textToParse = textToParse;

        All();
        
        try{
            if(this.error == false){
                System.out.println("parser.currentReduction(): "+parser.currentReduction());
                System.out.println("root: "+getRoot());
                System.out.println("arbol: "+this.arbol);
                System.out.println("****************************************************");
                showTree( this.arbol, getRoot(), parser.currentReduction());
                System.out.println("****************************************************");
            }
            //JScrollPane scroll = new JScrollPane(tree);
            //scroll.setBounds(0,0,300,100);
            //JFrame ventana = new JFrame();
            //ventana.add(scroll);
            //ventana.setVisible(true);
            parser.closeFile();
        }
        catch(ParserException parse){

            System.out.println("**PARSER ERROR**\n" + "parse.toString()");
            //System.exit(1);
            this.error = true;
            this.error_log+="** PARSER ERROR ** "+"\n\t"+ parse.toString() +"\n";
        }
    }

    /**
     * @return the root
     */
    public DefaultMutableTreeNode getRoot() {
        return root;
    }

    /**
     * @return the arbol
     */
    public JTree getJTree() {
        return this.jtree;
    }

    /**
     * @return the error
     */
    public boolean isError() {
        return error;
    }

    /**
     * @return the error_log
     */
    public String getError_log() {
        return error_log;
    }

    /**
     * @return the debug_log
     */
    public String getDebug_log() {
        return debug_log;
    }

    /**
     * @return the output_log
     */
    public String getOutput_log() {
        return output_log;
    }

    /**
     * @return the grammar
     */
    public static String getGrammar() {
        return grammar;
    }
    
    private String textToParse = "";
    private static final String compiledGrammar = "src/Grammar/Decaf_grammar4.cgt";
    private static final String grammar = "src/Grammar/Decaf_grammar4.grm";
    private DefaultMutableTreeNode root = new DefaultMutableTreeNode("Program");
    private DefaultTreeModel arbol = new DefaultTreeModel(root);
    private GOLDParser parser = new GOLDParser();
    private boolean error = false;
    private String error_log = "";
    private String debug_log = "";
    private String output_log = "";
    private JTree jtree = new JTree(this.arbol);

}